package com.jp.knowledge.my.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.my.model.HelpCateModel;
import com.jp.knowledge.util.ImageLoadUtil;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/6/21.
 */

public class HelpCateListAdapter extends RecycleVAdapter<HelpCateModel> {

	private boolean showIcon;

	public HelpCateListAdapter(Context context, @NonNull List<HelpCateModel> list) {
		this(context, list, false);
	}

	public HelpCateListAdapter(Context context, @NonNull List<HelpCateModel> list, boolean showIcon) {
		super(context, list);
		this.showIcon = showIcon;
	}

	@Override
	public int getLayoutId(int viewType) {
		return R.layout.item_help;
	}

	@Override
	public void onBind(RecycleVHolder holder, int position) {
		HelpCateModel data = getData(position);
		ImageView icon = holder.get(R.id.help_icon);
		TextView helpText = holder.getTextView(R.id.help_text);
		helpText.setText(data.getTitle());
		if(showIcon){
			icon.setVisibility(View.VISIBLE);
			ImageLoadUtil.load(mContext, data.getIcon(), icon);
			try{
//			helpText.setTextColor(Color.parseColor(data.getColor()));
				helpText.setTextColor(Color.parseColor("#777777"));
			} catch (Exception e){
				helpText.setTextColor(mContext.getResources().getColor(R.color.font_black_think));
			}
		} else {
			icon.setVisibility(View.GONE);
		}
	}
}
